//
//  JinRiMagazineHistoryViewController.m
//  JianChaRiBao
//
//  Created by 常兴宇 on 13-11-7.
//  Copyright (c) 2013年 wzyk. All rights reserved.
//

#import "JinRiMagazineHistoryViewController.h"
#import "JinRiMagazineCell.h"
#import "MagazineInfoViewController.h"
#import "AppDelegate.h"
@interface JinRiMagazineHistoryViewController ()
@end

@implementation JinRiMagazineHistoryViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        shouldSwipeBack = YES;
    }
    return self;
}
- (IBAction)backButtonClicked:(id)sender {
    [[UIApplication rootNavController] popViewControllerAnimated:YES];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    histroyGridView.leftContentInset = 20;
    histroyGridView.rightContentInset = 20;
    NSLog(@"info:%@",self.histroyArray);
    [histroyGridView reloadData];
}

-(NSUInteger)numberOfItemsInGridView:(AQGridView *)gridView{
    return self.histroyArray.count;
    
}
-(AQGridViewCell *)gridView:(AQGridView *)gridView cellForItemAtIndex:(NSUInteger)index{
    static NSString *CellIdentify = @"ListenCell";
    JinRiMagazineCell * cell = (JinRiMagazineCell *)[gridView dequeueReusableCellWithIdentifier:CellIdentify];
    if (cell == nil) {
        cell = [[JinRiMagazineCell alloc]initWithFrame:CGRectMake(0, 0, 70, 100) reuseIdentifier:CellIdentify];
    }
    cell.jinRiMagazineInfo = [self.histroyArray objectAtIndex:index];
    [cell updateDisplayWithImageStr:@"image"];
    
    return cell;
    
}
-(CGSize)portraitGridCellSizeForGridView:(AQGridView *)gridView{
    return CGSizeMake(80, 120);
}
- (CGRect)gridView:(AQGridView *)gridView adjustCellFrame:(CGRect)cellFrame withinGridCellFrame:(CGRect)gridCellFrame
{
    cellFrame.origin.y -= 5;
    return cellFrame;
}

-(void)gridView:(AQGridView *)gridView didSelectItemAtIndex:(NSUInteger)index{
    
    MagazineInfoViewController * magazineInfoViewController = [[[MagazineInfoViewController alloc]initWithNibName:@"MagazineInfoViewController" bundle:nil]autorelease];
    magazineInfoViewController.basicInfo = [_histroyArray objectAtIndex:index];
    [[UIApplication rootNavController] pushViewController:magazineInfoViewController animated:YES];
    [histroyGridView deselectItemAtIndex:index animated:YES];
}



- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)dealloc {
    [histroyGridView release];
    [super dealloc];
}
- (void)viewDidUnload {
    [histroyGridView release];
    histroyGridView = nil;
    [super viewDidUnload];
}
@end
